from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options
from service import service
from login_para import login


url = r'http://192.168.4.6/upload/'
username = 'admin'
password = 'root'
dr = webdriver.Chrome(options=options,service=service)
dr.get(url)
dr.maximize_window()

login = login(dr)
login.login(username, password)
# 发帖子
    # 默认版块
dr.find_element(By.XPATH,'//*[@id="category_1"]/table/tbody/tr[1]/td[2]/h2/a').click()
sleep(3)
    # 发帖子
dr.find_element(By.XPATH,'//*[@id="newspecial"]/img').click()
sleep(3)
    # 文本框标题内容
dr.find_element(By.ID,'subject').clear()
dr.find_element(By.ID,'subject').send_keys('第一个帖子')
sleep(3)
# 输入发帖的内容
    # 1、定位iframe框架
i=dr.find_element(By.XPATH,'//*[@id="e_iframe"]')
dr.switch_to.frame(i)
    # 2、输入发帖内容
dr.find_element(By.XPATH,'/html/body').clear()
dr.find_element(By.XPATH,'/html/body').send_keys('第一个帖子a')
sleep(3)
    # 3、跳出iframe框架
dr.switch_to.parent_frame()
sleep(3)
# 发表帖子
dr.find_element(By.ID,'postsubmit').click()
sleep(3)
login.logout()
sleep(3)